//
//  TUITextMessageCell.m
//  UIKit
//
//  Created by annidyfeng on 2019/5/30.
//

#import "LGTextMessageCell.h"
#import "TUIFaceView.h"
#import "TUICommonModel.h"
#import "TUIDefine.h"
#import "TUIGlobalization.h"
#import "NSString+TUIEmoji.h"
@implementation LGTextMessageCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.textView = [[TUITextView alloc] init];
        self.textView.backgroundColor = [UIColor clearColor];
        self.textView.textContainerInset = UIEdgeInsetsMake(0, 0, 0, 0);
        self.textView.textContainer.lineFragmentPadding = 0;
        self.textView.font = LGFont(16);
        self.textView.scrollEnabled = NO;
        self.textView.editable = NO;
        self.textView.delegate = self;
        [self.bubbleView addSubview:self.textView];
        [self.textView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.bubbleView).offset(10);
            make.left.equalTo(self.bubbleView).offset(16);
            make.bottom.equalTo(self.bubbleView).offset(-10);
            make.right.equalTo(self.bubbleView).offset(-16);
        }];
    }
    return self;
}

-(void)setDataDic:(NSDictionary *)dataDic{
    [super setDataDic:dataDic];
    NSString *sender = LGNSString(dataDic[@"sender"]);
    NSString *content = LGNSString(dataDic[@"content"][@"text"]);
    self.textView.attributedText = [content getFormatEmojiStringWithFont:LGFont(16) emojiLocations:[NSMutableArray array]];
    NSString *textColor = [sender isEqualToString:@"member"]?@"#333333":@"#FFFFFF";
    self.textView.textColor = [UIColor colorWithString:textColor];
    CGFloat maxWidth = [content boundingRectWithSize:CGSizeMake(MAXFLOAT, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:LGFont(16)} context:nil].size.width+35;
    maxWidth = MIN(maxWidth, TTextMessageCell_Text_Width_Max);
    [self.bubbleView mas_updateConstraints:^(MASConstraintMaker *make) {
        make.width.equalTo(@(maxWidth));
    }];
}

@end

